package com.xiyu.service.repository.mailbox.signature;

import com.xiyu.service.model.mailbox.signature.MailboxMailSignature;
import com.xiyu.service.model.mailbox.signature.MailboxMailSignatureTable;
import org.babyfish.jimmer.spring.repository.JRepository;

import java.util.Optional;
import java.util.List;

public interface MailboxMailSignatureRepository extends JRepository<MailboxMailSignature, Long> {
    MailboxMailSignatureTable mailboxMailSignatureTable = MailboxMailSignatureTable.$;

    default void updateContent(Long id, String content){
        sql().createUpdate(mailboxMailSignatureTable)
                .where(mailboxMailSignatureTable.id().eq(id))
                .set(mailboxMailSignatureTable.content(), content)
                .execute();
    }

    default void updateName(Long id, String name){
        sql().createUpdate(mailboxMailSignatureTable)
                .where(mailboxMailSignatureTable.id().eq(id))
                .set(mailboxMailSignatureTable.name(), name)
                .execute();
    }

    List<MailboxMailSignature> findByOwnerId(Long ownerId);

    Optional<MailboxMailSignature> findFirstByOwnerIdAndName(Long ownerId, String name);

}